package com.group3.controller;

import com.group3.cache.SeckillCache;
import com.group3.common.result.ApiResponse;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class CacheController {

    @GetMapping("/cache/repeatedSeckill")
    public ApiResponse<Boolean> repeatedSeckill(@RequestParam Integer uid, @RequestParam Integer pid) {
        boolean result = SeckillCache.repeatedSeckill(uid, pid);
        return ApiResponse.success(result);
    }

    @GetMapping("/cache/addRepeatedSeckillUser")
    public ApiResponse<Void> addRepeatedSeckillUser(@RequestParam Integer uid, @RequestParam Integer pid) {
        SeckillCache.addRepeatedSeckillUser(uid, pid);
        return ApiResponse.success("ok",  null);
    }

    @GetMapping("/cache/isStockOver")
    public ApiResponse<Boolean> isStockOver(@RequestParam Integer pid) {
        boolean result = SeckillCache.isStockOver(pid);
        return ApiResponse.success(result);
    }

    @GetMapping("/cache/markStockOver")
    public ApiResponse<Void> markStockOver(@RequestParam Integer pid) {
        SeckillCache.markStockOver(pid);
        return  ApiResponse.success("ok",  null);
    }
}
